package com.xuexiang.xuidemo.dialog;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.util.TextUtils;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.agp.window.dialog.PopupDialog;
import ohos.app.Context;

/**
 * 自定义PopupWindowDialog
 */
public class PopupWindowDialog extends PopupDialog {

    private ShapeElement mBackgroundDrawable;
    private  Context mContext;
    private Text mTvTitle;
    private Image mImlogin,mImsx,mIseting;
    private DirectionalLayout mDlCookie;
    private Text mTvMessage;
    private Text mTvAction;
    private Component  contentView;
    //private Component mComponent;
    public PopupWindowDialog(Context context, Component component){
        super(context,component);
        this.mContext=context;
        //this.mComponent=component;
        initViews();
    }
    private void initViews() {
        contentView = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_xui_popupwind_dialog,null,true);
        mBackgroundDrawable = new ShapeElement();
        mDlCookie=  (DirectionalLayout)contentView.findComponentById(ResourceTable.Id_cookie);
        mTvTitle=  (Text) contentView.findComponentById(ResourceTable.Id_tv_title);
        mTvMessage=  (Text) contentView.findComponentById(ResourceTable.Id_tv_message);
        mTvAction=  (Text) contentView.findComponentById(ResourceTable.Id_tv_action);
        mImlogin=  (Image) contentView.findComponentById(ResourceTable.Id_im_login);
        mImsx=  (Image) contentView.findComponentById(ResourceTable.Id_im_sx);
        mIseting=  (Image) contentView.findComponentById(ResourceTable.Id_im_seting);
        setCustomComponent(contentView);
    }

    /**
     * 背景颜色
     * @param backgroundColor
     */
    public  void setBackground(Color backgroundColor){
        mBackgroundDrawable.setRgbColor(RgbColor.fromArgbInt(backgroundColor.getValue()));
        mDlCookie.setBackground(mBackgroundDrawable);
    }


    /**
     * 设置弹出窗标题
     * @param title
     */
    public void setmTvTitle(String title) {
        if(!TextUtils.isEmpty(title)){
            mImlogin.setVisibility(Component.VISIBLE);
            mImlogin.setPixelMap(ResourceTable.Media_icon_password_login);
            mTvTitle.setMarginLeft(100);
            mTvTitle.setText(title);
        }
    }
    /**
     * 设置文本内容
     * @param message
     */
    public void setmTvMessage(String message) {
        if(!TextUtils.isEmpty(message)){
            mImsx.setVisibility(Component.VISIBLE);
            mImsx.setPixelMap(ResourceTable.Media_icon_filter);
            mTvMessage.setMarginLeft(100);
            mTvMessage.setText(message);
        }
    }

    public Text getmTvMessage() {
        return mTvMessage;
    }

    public Text getmTvTitle() {
        return mTvTitle;
    }

    public Text getmTvAction() {
        return mTvAction;
    }

    /**
     * 设置文字按钮
     * @param action
     */
    public void setmTvAction(String action) {
        if(!TextUtils.isEmpty(action)){
            mIseting.setVisibility(Component.VISIBLE);
            mIseting.setPixelMap(ResourceTable.Media_icon_setting);
            mTvAction.setMarginLeft(100);
            mTvAction.setText(action);
        }

    }
    /**
     * 设置按钮监听
     * @param listener
     */
    public void setmTvActionListener(Component.ClickedListener listener){
        mTvAction.setClickedListener(listener);

    }

    /**
     * 设置按钮监听
     * @param listener
     */
    public void setmTvMessageListener(Component.ClickedListener listener){
        mTvMessage.setClickedListener(listener);

    }

    /**
     * 设置按钮监听
     * @param listener
     */
    public void setmTvTitleListener(Component.ClickedListener listener){
        mTvTitle.setClickedListener(listener);

    }

}
